#include "report.h"

u16 a=333;
u8 x,y;
void ANO_Report(void)
{
        UsartReportedData(Dx,Dy,PID_Angle.ALL_out,0,0,0,0,0,0);  

}

void Data_Show(void)
{
    u8 buff[10]; 
	LCD_ShowString(0*WORD_X_INC,0*WORD_Y_INC, "X :",BLACK);
	LCD_ShowString(0*WORD_X_INC,1*WORD_Y_INC,"DS:",BLACK);
	LCD_ShowString(0*WORD_X_INC,2*WORD_Y_INC,"CH:",BLACK);
    LCD_ShowString(1*WORD_X_INC,0*WORD_Y_INC, "Y :",BLACK);
	LCD_ShowString(1*WORD_X_INC,1*WORD_Y_INC,"AG:",BLACK);
    LCD_ShowString(1*WORD_X_INC,2*WORD_Y_INC,"CH:",BLACK);
    sprintf(buff,"%3d",Dx);
	LCD_ShowString(1*NUM_X_INC-8,0*NUM_Y_INC,buff,BLACK);
    sprintf(buff,"%.1f",Distance);
	LCD_ShowString(1*NUM_X_INC-8,1*NUM_Y_INC,buff,BLACK);
    sprintf(buff,"%.1f",PID_Angle.ALL_out);
	LCD_ShowString(1*NUM_X_INC-8,2*NUM_Y_INC,buff,BLACK);
    sprintf(buff,"%3d",Dy);
	LCD_ShowString(3*NUM_X_INC-8,0*NUM_Y_INC,buff,BLACK);  
    sprintf(buff,"%3d",angle);
	LCD_ShowString(3*NUM_X_INC-8,1*NUM_Y_INC,buff,BLACK); 
    sprintf(buff,"%3d",a);
	LCD_ShowString(3*NUM_X_INC-8,2*NUM_Y_INC,buff,BLACK); 
}

void Rego_Show(void)
{
    u8 buff[10]; 
	LCD_ShowString(0*WORD_X_INC,3*WORD_Y_INC,"KP:",MAGENTA);
	LCD_ShowString(0*WORD_X_INC,4*WORD_Y_INC,"KI:",MAGENTA);
	LCD_ShowString(0*WORD_X_INC,5*WORD_Y_INC,"KD:",MAGENTA);
    LCD_ShowString(1*WORD_X_INC,3*WORD_Y_INC,"DS:",MAGENTA);
	LCD_ShowString(1*WORD_X_INC,4*WORD_Y_INC,"AG:",MAGENTA);
	LCD_ShowString(1*WORD_X_INC,5*WORD_Y_INC,"MO:",MAGENTA);
    sprintf(buff,"%.1f",PID_Angle.kp);
	LCD_ShowString(1*NUM_X_INC-8,3*NUM_Y_INC,buff,MAGENTA);
    sprintf(buff,"%.1f",PID_Angle.ki);
	LCD_ShowString(1*NUM_X_INC-8,4*NUM_Y_INC,buff,MAGENTA);
    sprintf(buff,"%.1f",PID_Angle.kd);
	LCD_ShowString(1*NUM_X_INC-8,5*NUM_Y_INC,buff,MAGENTA);
    sprintf(buff,"%.1f",Distance);
	LCD_ShowString(3*NUM_X_INC-8,3*NUM_Y_INC,buff,MAGENTA);  
    sprintf(buff,"%3d",angle);
	LCD_ShowString(3*NUM_X_INC-8,4*NUM_Y_INC,buff,MAGENTA); 
    sprintf(buff,"%3d",Mode);
	LCD_ShowString(3*NUM_X_INC-8,5*NUM_Y_INC,buff,MAGENTA); 
}

void Selec(void)
{
    static u8 last_x,last_y,IS_CHANGE;
    static float Inc;
    if(KEY_BUF[3].KEY_EVENT==KEY_UP)   
    {
        IS_CHANGE++;
        LCD_Fill(x*WORD_X_INC,y*WORD_Y_INC-9,x*WORD_X_INC+58,y*WORD_Y_INC-6,RED);
        if(IS_CHANGE==2)
            IS_CHANGE=0;
    }
    if(!IS_CHANGE)   
    {
        if(KEY_BUF[0].KEY_EVENT==KEY_UP)
            y++;
        if(KEY_BUF[1].KEY_EVENT==KEY_UP)
            y--;
        if(KEY_BUF[2].KEY_EVENT==KEY_UP)
            x--;
        if(KEY_BUF[4].KEY_EVENT==KEY_UP)
            x++;
        if(y<1)y=1;
        if(y>6)y=6;
        if(x<0)x=0;
        if(x>1)x=1;
        LCD_Fill(x*WORD_X_INC,y*WORD_Y_INC-9,x*WORD_X_INC+58,y*WORD_Y_INC-6,GREEN);
        if(x!=last_x||y!=last_y)
        LCD_Fill(last_x*WORD_X_INC,last_y*WORD_Y_INC-9,last_x*WORD_X_INC+58,last_y*WORD_Y_INC-6,WHITE);
        last_x=x;
        last_y=y;
    }
    if(IS_CHANGE)   
    {
        if(KEY_BUF[0].KEY_EVENT==KEY_DOWN)
            Inc-=(delta_value*(float)KEY_BUF[0].KEY_COUNT);
        if(KEY_BUF[1].KEY_EVENT==KEY_DOWN)
            Inc+=(delta_value*(float)KEY_BUF[0].KEY_COUNT);
        if(KEY_BUF[0].KEY_EVENT==KEY_DOWN||KEY_BUF[1].KEY_EVENT==KEY_DOWN)
        {
            switch(x)
            {
                case 0:
                    switch(y)
                    {
                        case 1:break;
                        case 2:break;
                        case 3:a+=Inc;break;
                        case 4:PID_Angle.kp+=Inc;PID_WriteFlash();break;
                        case 5:PID_Angle.ki+=Inc;PID_WriteFlash() ;break;
                        case 6:PID_Angle.kd+=Inc;PID_WriteFlash();break;
                    }
                    break;
                 case 1:
                    switch(y)
                    {
                        case 1:break;
                        case 2:break;
                        case 3:break;
                        case 4:Distance+=Inc;break;
                        case 5:angle+=Inc;break;
                        case 6:Mode+=Inc;break;
                    }
                    break;
            }
        }
        Inc=0;
    }
}

void TFT_Report(void)
{ 
    Selec();
    LCD_DrawLine(0,70,128,70,BLUE);
    LCD_DrawLine(0,71,128,71,BLUE);
    LCD_DrawLine(60,0,60,160,BLUE);
    LCD_DrawLine(61,0,61,160,BLUE);
    Data_Show();
    Rego_Show();
}


